﻿using Merge;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace UnitTestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Assert.IsTrue(Utils.FileNameContainKeyword("abc0.6", "0.6", true));
            Assert.IsTrue(Utils.FileNameContainKeyword("abc0.6d", "0.6", true));
            Assert.IsTrue(Utils.FileNameContainKeyword("0.6d", "0.6", true));
            Assert.IsTrue(Utils.FileNameContainKeyword(" 0.6d ", "0.6", true));
            Assert.IsTrue(Utils.FileNameContainKeyword("abc 0.6d", "0.6", true));
            Assert.IsTrue(Utils.FileNameContainKeyword("abc0.6 d", "0.6", true));
        }

        [TestMethod]
        public void TestMethod2()
        {
            Assert.IsFalse(Utils.FileNameContainKeyword("abc10.6", "0.6", true));
        }

        [TestMethod]
        public void TestMethod2D1()
        {
            Assert.IsFalse(Utils.FileNameContainKeyword("abc0.67", "0.6", true));
        }

        [TestMethod]
        public void TestMethod3()
        {
            Assert.IsTrue(Utils.FileNameContainKeyword("abc0.6", "06", true));
        }

        [TestMethod]
        public void TestMethod4()
        {
            Assert.IsTrue(Utils.FileNameContainKeyword("abc06", "0.6", true));
        }

        [TestMethod]
        public void TestMethod5()
        {
            Assert.IsFalse(Utils.FileNameContainKeyword("abc0.6", "06", false));
            Assert.IsFalse(Utils.FileNameContainKeyword("abc06", "0.6", false));
        }


        [TestMethod]
        public void TestMethodExtractCopyCount()
        {
            Assert.AreEqual("1", Utils.ExtractCopyCounts("abc1套0.6"));
            Assert.AreEqual("2", Utils.ExtractCopyCounts("abc2件0.6"));
            Assert.AreEqual("11", Utils.ExtractCopyCounts("abc11件0.6"));
        }

        [TestMethod]
        public void TestMethodExtractCopyCountZh()
        {
            Assert.AreEqual("一", Utils.ExtractCopyCounts("abc一套0.6"));
            Assert.AreEqual("二", Utils.ExtractCopyCounts("abc二件0.6"));
        }

        [TestMethod]
        public void TestMethodCopyCountsToIntStr()
        {
            Assert.AreEqual("1", Utils.ExtractCopyCountsToIntStr("abc1套0.6"));
            Assert.AreEqual("2", Utils.ExtractCopyCountsToIntStr("abc2件0.6"));
            Assert.AreEqual("1", Utils.ExtractCopyCountsToIntStr("abc一套0.6"));
            Assert.AreEqual("10", Utils.ExtractCopyCountsToIntStr("abc十件0.6"));
        }


        [TestMethod]
        public void TestMethodFilter()
        {
            List<Cell> cells = new List<Cell>();
            Cell c1 = new Cell("a bc def 0.6 07.dxf");
            Cell c2 = new Cell("a bc def 0.36 07.dxf");
            Cell c3 = new Cell("a bc def yz 0.6 07.dxf");
            Cell c4 = new Cell("a bc def 06 07.dxf");
            Cell c5 = new Cell("a bc def 6 7.dxf");

            cells.Add(c1);
            cells.Add(c2);
            cells.Add(c3);
            cells.Add(c4);

            Filter f1 = new Filter()
            {
                Name = "filter1",
                SortingNumber = 1,
                Selected = true,
                IncludeKeywords = new string[] { "bc", "0.6" },
                ExcludeKeywords = new string[] { "yz" },
            };

            Filter f2 = new Filter()
            {
                Name = "filter2",
                SortingNumber = 2,
                Selected = true,
                IncludeKeywords = new string[] { "yz", "0.6" },
                ExcludeKeywords = new string[] { "dfsd" },
            };


            Filters filters = new Filters() { FuzzyMatchDot = true, AllFilters = new Filter[] { f1, f2 } };

            Assert.IsTrue(Utils.WithInFilter(filters, c1));
            Assert.AreEqual("filter1", c1.FilterName);
            Assert.IsFalse(Utils.WithInFilter(filters, c2));
            Assert.IsTrue(Utils.WithInFilter(filters, c3));
            Assert.AreEqual("filter2", c3.FilterName);
            Assert.IsTrue(Utils.WithInFilter(filters, c4));
            Assert.AreEqual("filter1", c4.FilterName);
            Assert.IsFalse(Utils.WithInFilter(filters, c5));

        }
    }
}
